<template>
	<view :class="isDark?'darkBg':''">
		<cu-custom :bgColor="isDark?'bg-black':'bg-blue'" isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">课表总揽</block>
		</cu-custom>

		<view :class="isDark?'dark':''">
			<view style="height: 545rpx; background-size: cover;  background-position: center;"
				:style="{backgroundImage:isDark?'url(https://web.cloudduolc.cn/image/adblack7.png)':'url(https://web.cloudduolc.cn/image/adwhite5.png)'}">
			<ad unit-id="adunit-3cbf7fe84db5a52b" ad-type="video" :ad-theme="isDark?'black':'white'"></ad>
			</view>
			<view class="cu-bar bg-white solid-bottom" style="font-weight:bold" :class="isDark?'dark':'bg-white'">
				<view class="action">
					<text class="cuIcon-titles text-blue"></text>课表总揽
					<text class="cuIcon-search"></text>
				</view>
			</view>

			<scroll-view scroll-x class=" nav text-center" :class="isDark?'dark':'bg-white'">
				<view class="cu-item" :class="0==TabCur?'text-blue cur':''" @tap="tabSelect" data-id="0">
					学校
				</view>
				<view class="cu-item" :class="1==TabCur?'text-blue cur':''" @tap="tabSelect" data-id="1">
					自定义
				</view>
			</scroll-view>
			<view v-if="TabCur!=1">
				<view class=" padding flex flex-direction" :class="isDark?'dark':'bg-white'">
					<button class="cu-btn round bg-blue text-white lg">学校课程总数:{{num}}</button>
				</view>

				<view class="padding  text-grey  shadow-warp cu-list menu card-menu" :class="isDark?'darkIn':'bg-white'"
					style="border: 3rpx solid #000000;">
					<view v-if="seeList.length<=0" style="text-align: center;font-size: 40rpx;"
						class="margin-left margin-right" :class="isDark?'darkIn':'bg-white'">


						<image src="../../../static/score/empty.png"
							style="width: 600rpx;height: 600rpx;margin-top: 0rpx;">
						</image>
					</view>
					<view class="" v-for="(val,index) in seeList" :key="index" class="solids-bottom">
						<view class="padding  radius" :class="isDark?'darkIn':'bg-white'" v-if="val.place!='1'">
							<view>
								<!-- <span style="width:50rpx;font-weight:bold;color:#6739b6;">{{index+1}}</span> -->
								<view class="margin-top">{{index+1}}</view>
								<view class="margin-top">课程名称:<span class="margin-left">{{val.courseName}}</span></view>
								<view class="margin-top">老师:<span class="margin-left">{{val.teacher}}</span></view>
								<view class="margin-top">地点:<span class="margin-left">{{val.place}}</span></view>
								<view class="margin-top">星期:<span class="margin-left">{{val.week}}</span></view>
								<view class="margin-top">周数:<span class="margin-left">{{val.weekNum}}</span></view>
								<view class="margin-bottom-xl margin-top">节次:<span
										class="margin-left">{{val.course}}</span>
									<button class="cu-btn bg-red text-sm margin-bottom-xl fr margin-top"
										@tap="deleteStorage" :data-index="index">删</button>
								</view>

							</view>

						</view>

					</view>

				</view>
			</view>
			<view v-if="TabCur!=0">
				<view class=" padding flex flex-direction" :class="isDark?'dark':'bg-white'">
					<button class="cu-btn round bg-blue text-white lg">自定义课程总数:{{customNum}}</button>
				</view>

				<view class="padding text-grey  shadow-warp cu-list menu card-menu" :class="isDark?'darkIn':'bg-white'"
					style="border: 3rpx solid #000000;">
					<view v-if="customList.length<=0" style="text-align: center;font-size: 40rpx;"
						class="margin-left margin-right" :class="isDark?'darkIn':'bg-white'">


						<image src="../../../static/score/empty.png"
							style="width: 600rpx;height: 600rpx;margin-top: 0rpx;">
						</image>
					</view>
					<view class="" v-for="(val,index) in customList" :key="index" class="solids-bottom">
						<view class="padding  radius" :class="isDark?'darkIn':'bg-white'">
							<view>
								<!-- <span style="width:50rpx;font-weight:bold;color:#6739b6;">{{index+1}}</span> -->
								<view class="margin-top">{{index+1}}</view>
								<view class="margin-top ">课程名称:<span class="margin-left">{{val.courseName}}</span>
								</view>
								<view class="margin-top">老师:<span class="margin-left">{{val.teacher}}</span></view>
								<view class="margin-top">地点:<span class="margin-left">{{val.place}}</span></view>
								<view class="margin-top">星期:<span class="margin-left">{{val.week}}</span></view>
								<view class="margin-top">周数:<span class="margin-left">{{val.weekNum}}</span></view>
								<view class="margin-bottom-xl margin-top">节次:<span
										class="margin-left">{{val.startCourse}}-{{val.endCourse}}</span>
									<button class="cu-btn bg-red text-sm margin-bottom-xl fr  margin-top"
										@tap="deleteCustomStorage" :data-index="index">删</button>
								</view>

							</view>

						</view>

					</view>

				</view>
			</view>
			<view class="padding flex flex-wrap " :class="isDark?'dark':'bg-white'">


			</view>
			<view class="cu-tabbar-height"></view>

		</view>
		<zmm-watermark>

		</zmm-watermark>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [],
				seeList: [],
				customList: [],
				total: 0,
				num: 0,
				customNum: 0,
				isDark: this.isDark,
				TabCur: 0,



			}
		},
		onShow() {
			let _this = this

			const myTimetable = _this.$store.state.myTimetable

			if (myTimetable.length != undefined) {
				_this.list = myTimetable

			}

			const myCustomTimetable = _this.$store.state.myCustomTimetable

			if (myCustomTimetable.length != undefined) {
				_this.customNum = myCustomTimetable.length;
				_this.customList = myCustomTimetable
			}


			_this.setData()

		},
		methods: {
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60
			},
			setData() {
				let _this = this
				_this.num = 0
				_this.seeList = []
				for (var k = 0; k < _this.list.length; k++) {
					_this.seeList[k] = {
						courseName: '1',
						place: '1',
						course: '1',
						week: '1',
						weekNum: '1',
					}
				}
				for (var i = 0; i < _this.list.length; i++) {
					//console.log(_this.list[i].courseName)
					for (var j = 0; j < _this.seeList.length; j++) {
						if ((_this.seeList[j].courseName == _this.list[i].courseName)) {
							//console.log("相同")
							//console.log()
							if (_this.seeList[j].place.indexOf(_this.list[i].place) == -1) {
								_this.seeList[j].place += " / " + _this.list[i].place
							}
							if (_this.seeList[j].weekNum.indexOf(_this.list[i].weekNum) == -1) {
								_this.seeList[j].weekNum += " / " + _this.list[i].weekNum
							}
							if (_this.seeList[j].week.indexOf("星期" + _this.list[i].week) == -1) {
								_this.seeList[j].week += " / " + "星期" + _this.list[i].week
							}
							if (_this.seeList[j].course.indexOf("" + _this.list[i].startCourse + "-" + _this.list[i]
									.endCourse) == -1) {
								_this.seeList[j].course += " / " + _this.list[i].startCourse + "-" + _this.list[i]
									.endCourse
							}


							break;
						} else {
							//console.log("不同:" + _this.seeList[j].place)
							if (_this.seeList[j].place == '1') {
								//console.log("不存在" + j)
								//console.log(_this.seeList[j])
								// var newObj = 
								_this.seeList[j] = {
									courseName: _this.list[i].courseName,
									place: _this.list[i].place,
									course: "" + _this.list[i].startCourse + "-" + _this.list[i].endCourse,
									week: "星期" + _this.list[i].week,
									weekNum: _this.list[i].weekNum,
									teacher: _this.list[i].teacher,
								}
								//console.log(_this.seeList[j])
								//console.log("跳出:" + j)
								_this.num += 1
								break
							} else {
								//console.log("存在")

							}

						}
					}
					//console.log(_this.seeList)
				}
			},
			deleteCustomStorage: function(e) {

				let _this = this
				var index = e.currentTarget.dataset.index;
				uni.showModal({
					title: '提示',
					content: '是否确认删除',
					confirmText: "确认",
					cancelText: "在想想",
					success: function(res) {
						if (res.confirm) {
							var arr = _this.customList
							arr.splice(index, 1)
							//console.log(arr)
							_this.customNum = arr.length;
							_this.$store.commit('myCustomTimetable', arr)
							uni.showToast({
								title: "删除成功",
								icon: "none"
							})

						} else if (res.cancel) {
							console.log("点击了取消")
						} else {
							console.log("点击了别的")
						}
					}
				});
			},
			deleteStorage(e) {
				let _this = this
				var index = e.currentTarget.dataset.index;
				uni.showModal({
					title: '提示',
					content: '是否确认删除',
					confirmText: "确认",
					cancelText: "在想想",
					success: function(res) {
						if (res.confirm) {
							var arr = _this.list
							var newArr = []
							var courseName = _this.seeList[index].courseName
							for (var i = 0; i < arr.length; i++) {
								if (_this.list[i].courseName == courseName) {

								} else {
									newArr.push(_this.list[i])
								}

							}
							console.log(courseName)
							_this.list = newArr
							_this.$store.commit('myTimetable', newArr)
							uni.showToast({
								title: "删除成功",
								icon: false
							})
							_this.setData()

						} else if (res.cancel) {
							console.log("点击了取消")
						} else {
							console.log("点击了别的")
						}
					}
				});
			}

		}

	}
</script>

<style>

</style>
